Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use file input in payForBlobs CLI to allow to submit multiple blobs #2856

Merged
merged 41 commits into from
Dec 5, 2023

Conversation

bao1029p
Copy link
Contributor

@bao1029p bao1029p commented Nov 19, 2023

Close #2434

Changes made

  • Add blobJson proto type define how user can submit blob in file
  • Add file path as argument input for payForBlob command
  • Add parseSubmitBlobs to parse content from the file to array of defined blobJSON. Each blobJSON contain a namespaceID and blob in hex encoded format ( can modify what the user can put in the file later on, this need further conversation on this )
  • Modifed the broadcastPFB func to accept multiple blobs instead

Testing

test the command with single-node script running and got this result ( thanks @sontrinh16 for providing the test result )
image

using the test_blob.json file contain:
{ "Blobs": [ { "namespaceId": "0x00010203040506070809", "blob": "0x48656c6c6f2c20576f726c6421" }, { "namespaceId": "0x00010203040506070809", "blob": "0x48656c6c6f2c20576f726c6421" } ] }

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

Copy link
Contributor

coderabbitai bot commented Nov 19, 2023

Note

Reviews Paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

@bao1029p
Copy link
Contributor Author

@coderabbitai pause

@codecov-commenter
Copy link

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (9b5d025) 19.16% compared to head (25324ba) 19.16%.

Files Patch % Lines
cmd/celestia-appd/cmd/download_genesis.go 0.00% 5 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2856   +/-   ##
=======================================
  Coverage   19.16%   19.16%           
=======================================
  Files         142      142           
  Lines       17291    17285    -6     
=======================================
  Hits         3313     3313           
+ Misses      13676    13670    -6     
  Partials      302      302           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sontrinh16
Copy link
Contributor

sontrinh16 commented Nov 29, 2023

@bao1029p hey gud ser can i have permision to push some code to this PR

@bao1029p
Copy link
Contributor Author

@bao1029p hey gud ser can i permision to push some code to this PR

yes plss feel free to contribute to this PR

@bao1029p bao1029p changed the title Use file input feat: Use file input in payForBlobs CLI to allow to submit multiple blobs Nov 29, 2023
@bao1029p
Copy link
Contributor Author

thanks @sontrinh16 for the help, i think we are close command work now, will do some testing

@bao1029p
Copy link
Contributor Author

i think this is a rough working version for now, happy to change any logic

@bao1029p bao1029p marked this pull request as ready for review November 30, 2023 14:39
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dope left a few comments on things I think we should handle but otherwise this is a really great start. thanks for doing this @bao1029p !!

proto/celestia/core/v1/blob/blob.proto Outdated Show resolved Hide resolved
shareVersion, _ := cmd.Flags().GetUint8(FlagShareVersion)
blob, err := types.NewBlob(namespace, rawblob, shareVersion)
if err != nil {
fmt.Printf("failure to create blob with hex blob value %s: %s", hexStr, err.Error())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking]
as is would this submit a transaction without the blob that failed? if that's the case then I think we need to return with error. that could be immediatly or using something like multierror

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes agreed will update this

Comment on lines 51 to 67
if len(args) < 2 {
return fmt.Errorf("PayForBlobs requires two arguments: namespaceID and blob")
if len(args) < 1 {
return fmt.Errorf("PayForBlobs requires one arguments: path to blob.json")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking]
I think there's a way to avoid a breaking change, and we should pursue that. for example we could use a flag to indicate that its pointing to json file (or accepted piped input etc). we could even check if the input has the last five characters equal to ".json" and then proceed to try and parse a json

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the check, thanks for the suggestion

Comment on lines 33 to 34
// FlagNamespaceVersion allows the user to override the namespace version when
// submitting a PayForBlob.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] this GoDoc isn' related to the flag it's documenting. It should look something like:

	// FlagBlobsFilePath allows the user to...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as requested


// FlagNamespaceVersion allows the user to override the namespace version when
// submitting a PayForBlob.
FlagBlobsFilePath = "blobs-file-path"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] this flag appears unused. I think the command below should only read blobs from a file path if the optional flag is provided.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have move the file input to a optional flag instead of argument

)

func CmdPayForBlob() *cobra.Command {
cmd := &cobra.Command{
Use: "PayForBlobs namespaceID blob",
Use: "PayForBlobs [namespaceID, blob] [path/to/blob.json]",
Copy link
Collaborator

@rootulp rootulp Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] this usage statement is a bit confusing. The [] usually describes a optional group. Here both groups are optional but that's not really the case. The command accepts one or the other.

I think we should take a step back and design the user experience.

Non-breaking approach

IMO this command should accept one namespaceID and blob. Ex.

celestia-appd tx blob PayForBlobs namespaceID blob

or multiple blobs

celestia-appd tx blob PayForBlobs --input-file path/to/blobs.json

Breaking approach

We split this into two commands (PayForBlob and PayForBlobs) and remove the aliases

celestia-appd tx blob PayForBlob namespaceID blob
celestia-appd tx blob PayForBlobs path/to/blobs.json

Comment on lines 42 to 47
Example: "celestia-appd tx blob PayForBlobs path/to/blob.json \\\n" +
"\t--chain-id private \\\n" +
"\t--from validator \\\n" +
"\t--keyring-backend test \\\n" +
"\t--fees 21000utia \\\n" +
"\t--yes",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] if we do the non-breaking approach where this command supports both one blob and multiple blobs, then this Example section should contain both examples

$ celestia-appd tx blob PayForBlobs --help
<truncated>
Examples:
celestia-appd tx blob PayForBlobs 0x00010203040506070809 0x48656c6c6f2c20576f726c6421 \
	--chain-id private \
	--from validator \
	--keyring-backend test \
	--fees 21000utia \
	--yes

celestia-appd tx blob PayForBlobs --input-file path/to/blobs.json \
	--chain-id private \
	--from validator \
	--keyring-backend test \
	--fees 21000utia \
	--yes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added as suggested

Comment on lines 48 to 49
Short: "Pay for a data blobs to be published to Celestia.",
Long: "Pay for a data blobs to be published to Celestia.\n" +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Short: "Pay for a data blobs to be published to Celestia.",
Long: "Pay for a data blobs to be published to Celestia.\n" +
Short: "Pay for data blob(s) to be published to Celestia.",
Long: "Pay for data blob(s) to be published to Celestia.\n" +

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Short: "Pay for a data blobs to be published to Celestia.",
Long: "Pay for a data blobs to be published to Celestia.\n" +
"User can use namespaceID and blob or path to a json file as argument" +
`Where blob.json contains:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] To enhance the user experience, it would be beneficial to consider the implementation of flexible file naming conventions, rather than restricting to a specific file name like blob.json. This can be achieved by allowing users to include their chosen file name in the filepath, which then can be parsed accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, i think i need to specify that blob.json is an example file name

@celestia-bot celestia-bot requested a review from a team December 4, 2023 19:53
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one comment from the linter otherwise lgtm. thanks @bao1029p

if len(args) < 2 {
return fmt.Errorf("PayForBlobs requires two arguments: namespaceID and blob")
return fmt.Errorf("PayForBlobs requires two argument: namespaceID and blob")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're going to use fmt.Errorf, then we should include something to format in the string other wise I think the linter is going to block us

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as request

@celestia-bot celestia-bot requested a review from a team December 4, 2023 21:33
evan-forbes
evan-forbes previously approved these changes Dec 4, 2023
@cmwaters
Copy link
Contributor

cmwaters commented Dec 5, 2023

Just as an aside, I don't know why we use camel case for PayForBlobs in the cli. No other command uses capitalized letters. It's all lower case iirc

Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work! Thanks for persisting through multiple rounds of review. I have one nit and then this LGTM

x/blob/client/cli/payforblob.go Outdated Show resolved Hide resolved
@celestia-bot celestia-bot requested a review from a team December 5, 2023 16:26
@rootulp rootulp requested a review from evan-forbes December 5, 2023 16:26
@rootulp rootulp merged commit 4d08a7f into celestiaorg:main Dec 5, 2023
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(blob): allow for more than one blob to be sumbmitted via the CLI
7 participants